package cn.monkey.family.data.shop.item.comment;

import cn.monkey.family.data.EntityMapper;
import cn.monkey.family.data.TreeMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Collection;

@Mapper(unmappedTargetPolicy = org.mapstruct.ReportingPolicy.IGNORE)
public abstract class CommentMapper extends EntityMapper<CommentDto, Comment, CommentVo>
        implements TreeMapper<String, Comment, CommentVo> {


    @Override
    @Mapping(target = "creator", source = "creatorId", qualifiedByName = "getUserIdAndNamePairFromId")
    @Mapping(target = "updater", source = "updaterId", qualifiedByName = "getUserIdAndNamePairFromId")
    public abstract CommentVo toVo(Comment comment);

    @Override
    public abstract Comment toEntity(CommentDto commentDto);

    public Collection<CommentVo> toTree(Collection<Comment> comments, Integer maxDeep) {
        return TreeMapper.super.toTree(comments, this::toVo, Comment::getId, Comment::getParentId, CommentVo::setChild, maxDeep);
    }
}
